const TokenKey = 'App-Token'

export function getToken(token = TokenKey) {
	const data = uni.getStorageSync(TokenKey);
	if (typeof data === 'string') {
		try {
			return JSON.parse(data);
		} catch (e) {
			return data;
		}
	}

	return data;
}

export function setToken(key = TokenKey, value) {
	return uni.setStorageSync(key, value)
}

export function removeToken() {
	return uni.removeStorageSync(TokenKey)
}

export function getStroge(key) {
	const data = uni.getStorageSync(key);
	if (typeof data === 'string') {
		try {
			return JSON.parse(data);
		} catch (e) {
			return data;
		}
	}

	return data;
}

export function setStroge(key = TokenKey, value) {
	return uni.setStorageSync(key, value)
}

export function removeStroge() {
	return uni.removeStorageSync(TokenKey)
}